package com.turbo.boot.crawler.controller.admin;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.turbo.boot.crawler.dao.entity.CrawlerConfigEntity;
import com.turbo.boot.crawler.service.ICrawlerConfigService;
import com.turbo.framework.annatation.TurboRestController;
import com.turbo.starter.base.rest.BaseController;
import com.turbo.starter.mybatis.CrudOption;
import io.swagger.v3.oas.annotations.tags.Tag;

import javax.servlet.http.HttpServletRequest;

/**
 * Sofr
 */
@Tag(name = "爬虫配置", description = "爬虫配置")
@TurboRestController(value = "/admin/crawler/config", api = {"add", "delete", "update", "page", "list", "info"})
public class AdminCrawlerConfigController extends BaseController<ICrawlerConfigService, CrawlerConfigEntity> {


    @Override
    protected void init(HttpServletRequest request, JSONObject requestParams) {

        CrudOption<CrawlerConfigEntity> crudOption = createOp()
                .fieldEq("groupId").keyWordLikeFields("name", "brief", "target_urls");
        crudOption.queryWrapper(new QueryWrapper<CrawlerConfigEntity>().orderByAsc(crudOption.getField("createdAt")));
        setListOption(crudOption);
        setPageOption(crudOption);
    }
}